package com.pan.admin.module.loanProduct.controller;

import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.module.channel.service.LoanChannelService;
import com.pan.admin.module.loanProduct.entity.po.LoanProductRechargePO;
import com.pan.admin.module.loanProduct.entity.qo.LoanProductKeywordQO;
import com.pan.admin.module.loanProduct.entity.qo.LoanProductPlanKeywordQO;
import com.pan.admin.module.loanProduct.entity.qo.LoanProductRechargeQO;
import com.pan.admin.module.loanProduct.service.LoanProductPlanService;
import com.pan.admin.module.loanProduct.service.LoanProductRechargeService;
import com.pan.admin.module.loanProduct.service.LoanProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 机构充值记录
 *
 * @author caoxin
 */
@RestController
public class LoanProductRechargeController extends BaseController {

    @Autowired
    private LoanProductRechargeService loanProductRechargeService;
    @Autowired
    private LoanChannelService loanChannelService;
    @Autowired
    private LoanProductService loanProductService;
    @Autowired
    private LoanProductPlanService loanProductPlanService;

    /**
     * api渠道
     */
    @GetMapping("/org/recharge/listApiKey")
    @PreAuthorize("@ss.hasPermi('org:recharge:list')")
    public AjaxResult listApiKey(@RequestParam(required = false) String keyword) {
        return AjaxResult.success(this.loanChannelService.listLoanChannel(keyword));
    }

    /**
     * 主体
     */
    @GetMapping("/org/recharge/listLoanProduct")
    @PreAuthorize("@ss.hasPermi('org:recharge:list')")
    public AjaxResult listLoanProduct(@RequestParam(required = false) String keyword) {
        LoanProductKeywordQO LoanProductKeywordQO = new LoanProductKeywordQO();
        LoanProductKeywordQO.setKeyword(keyword);
        return AjaxResult.success(this.loanProductService.listLoanProductWithDataScope(LoanProductKeywordQO));
    }

    /**
     * 计划
     */
    @GetMapping("/org/recharge/listLoanProductPlan")
    @PreAuthorize("@ss.hasPermi('org:recharge:list')")
    public AjaxResult listLoanProductPlan(@RequestParam(required = false) List<Long> loanProductId, @RequestParam(required = false) String keyword) {
        LoanProductPlanKeywordQO loanProductPlanKeywordQO = new LoanProductPlanKeywordQO();
        loanProductPlanKeywordQO.setLoanProductId(loanProductId);
        loanProductPlanKeywordQO.setKeyword(keyword);
        return AjaxResult.success(this.loanProductPlanService.listLoanProductPlanWithDataScope(loanProductPlanKeywordQO));
    }

    /**
     * 查询机构充值记录列表
     */
    @GetMapping("/org/recharge/list")
    @PreAuthorize("@ss.hasPermi('org:recharge:list')")
    public TableDataInfo list(LoanProductRechargeQO loanProductRechargeQO) {
        startPage();
        List<LoanProductRechargePO> list = this.loanProductRechargeService.listWithDataScope(loanProductRechargeQO);
        return getDataTable(list);
    }

}
